package action;


import java.util.UUID;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import pageModel.Good;
import pageModel.IdWorker;
import pageModel.Json;
import service.CashierServiceI;
import service.GoodServiceI;

import com.opensymphony.xwork2.ModelDriven;

@Namespace("/")
@Action(value="cashierAction")
public class CashierAction extends BaseAction implements ModelDriven<Good>{
Good good=new Good();
private String goodid;
private CashierServiceI cashierService;
private GoodServiceI goodService;
	@Override
	public Good getModel() {
		return good;
	}
	public CashierServiceI getCashierService() {
		return cashierService;
	}
	@Autowired
	public void setCashierService(CashierServiceI cashierService) {
		this.cashierService = cashierService;
	}
	
	public GoodServiceI getGoodService() {
		return goodService;
	}
	@Autowired
	public void setGoodService(GoodServiceI goodService) {
		this.goodService = goodService;
	}
	
	public String getGoodid() {
		return goodid;
	}
	public void setGoodid(String goodid) {
		this.goodid = goodid;
	}
	public void show(){
		super.writeJson(cashierService.show(good));
		/*cashierService.save(good);*/
	}
	public void getOrderId()
    {   
		Json j=new Json();
		IdWorker worker2 = null;
        String uuid = UUID.randomUUID().toString().replace("-", ""); 
        String  str1 = uuid.substring(2, 4); 
        String  str2 = uuid.substring(9, 10);
        String  str3 = uuid.substring(25, 27);
        String str=str1+str2+str3;
        int strInteger = Integer.parseInt(str, 16); 
        worker2 = new IdWorker(strInteger);
        j.setSuccess(true);
        j.setMessage(worker2.nextId());
        super.writeJson(j); 
    }
}
